﻿using System;
using System.Windows;
using Caffeine.Model;
using Caffeine.ChangeRecognitionPOC.ViewModel;
using System.Windows.Controls;
using System.Windows.Data;
using System.Threading;

namespace Caffeine.ChangeRecognitionPOC
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            FormViewModel[] viewModels = new FormViewModel[] { new FormViewModel(), new FormViewModel(), new FormViewModel() };
            viewModels[0].Name.Value = "Tab 1 Parent";
            viewModels[1].Name.Value = "Tab 2 Parent";
            viewModels[2].Name.Value = "Tab 3 Parent";

            CreateChildViewModels(5, 1, viewModels[0]);
            CreateChildViewModels(5, 1, viewModels[1]);
            CreateChildViewModels(5, 1, viewModels[2]);

            viewModels[0].CommitGraph();
            viewModels[1].CommitGraph();
            viewModels[2].CommitGraph();

            DataContext = viewModels;
            CollectionViewSource.GetDefaultView(viewModels).MoveCurrentToFirst();
        }

        private void CreateChildViewModels(Int32 maxLevel, Int32 currentLevel, FormViewModel parent)
        {
            for (Int32 index = 0; index < 2; index++)
            {
                FormViewModel viewModel = new FormViewModel();
                viewModel.AlternatingIndex.Value = currentLevel % 2;

                viewModel.Name.Value = String.Format("Form View {0}-{1}", currentLevel, index);

                if (currentLevel < maxLevel)
                {
                    CreateChildViewModels(maxLevel, currentLevel + 1, viewModel);
                }

                parent.ChildViewModels.Add(viewModel);
            }
        }

        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
        }
    }
}
